#include "cmsis_os.h"

#include "main.h"

#include "task.h"

static osThreadId_t printTaskHandle;

static void showTaskInformation(void* argument);

static const osThreadAttr_t defaultTask_attributes = {
  .name = "printTask",
  .stack_size = 128*2,
  .priority = (osPriority_t) osPriorityNormal1,
};


void printTaskInit(void){
    printTaskHandle = osThreadNew(showTaskInformation, NULL, &defaultTask_attributes);

}


static void showTaskInformation(void* argument){
    BaseType_t val;

    char pcWriteBuffer[200];


    for(uint8_t i = 0; i<10; i++){
        vTaskList(pcWriteBuffer);
        printf("[loop:%d]-----------------\r\n", i);
        printf("Name      State   Priority  Stack   Num\r\n");
        printf("%s\r\n", pcWriteBuffer);    
        /*check history */
        printf("Total FreeRtos Memory Size:%d bytes.\r\n", configTOTAL_HEAP_SIZE);

        printf("FreeRtos Memory Left:%d bytes.\r\n", xPortGetFreeHeapSize());

        printf("FreeRtos Memory Min Left:%d bytes.\r\n", xPortGetMinimumEverFreeHeapSize());

        val = uxTaskGetStackHighWaterMark(printTaskHandle);

        printf("Mini Memory Left for print task:%d bytes.\r\n", val*4);   

        osDelay(1000);
    }
    osThreadExit();

}